package fr.afcepf.atod19.dreamproject.managedBeans;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fr.afcepf.atod19.dreamproject.business.interfaces.IBusinessCatalogue;
import fr.afcepf.atod19.dreamproject.entity.Reve;

@ManagedBean(name = "autoCompletionMB")
@RequestScoped
public class AutoCompletionMB {

	static Logger logger = LoggerFactory.getLogger(AccueilMB.class);

	@ManagedProperty(value = "#{businessCatalogue}")
	private IBusinessCatalogue businessCatalogue;

	private String recherche;
	private List<String> suggestions;

	private final int nbReveAffiches = 5;
	private final int page = 0;
	
	public void rechercher(){
		
	}

	public IBusinessCatalogue getBusinessCatalogue() {
		return businessCatalogue;
	}

	public void setBusinessCatalogue(IBusinessCatalogue businessCatalogue) {
		this.businessCatalogue = businessCatalogue;
	}

	public String getRecherche() {
		return recherche;
	}

	public void setRecherche(String recherche) {
		this.recherche = recherche;
	}

	public List<String> getSuggestions() {
		List<Reve> reves = businessCatalogue.getRevesPaginesParNom(recherche,
				nbReveAffiches, page);

		suggestions = new ArrayList<>();
		if (reves != null) {
			for (Reve reve : reves) {
				suggestions.add(reve.getNom());
			}
		}
		suggestions.add("pouet");
		System.out.println("ça passe");
		return suggestions;
	}

	public void setSuggestions(List<String> suggestions) {
		this.suggestions = suggestions;
	}

}
